/**
 * @Date 2023-02-21 14:00:07
 * @Remark
 */

// lib
// config
// script & methods & public
import logUtils from "utils/logUtils";
// store
import { state } from "./state";
// service
import toast from "components/toast";
import { getShelfLongPageService } from "biz/Books/service";
import { ReqBookPage } from "biz/Books/api";
import { ReqBorrowPage } from "biz/Borrow/api";
import { confirmOutRecordService, getOutRecordPageService } from "biz/Borrow/service";
// 其它
 
// 出库单分页列表
export async function getOutRecordPage() {
  const sp = state.getSearch();
  logUtils.info("搜索参数", sp);
  const params: ReqBorrowPage = {
    ...sp,
    pageNum: state.page,
    pageSize: state.size,
  };
  // 调用服务
  state.loading = true;
  const result = await getOutRecordPageService(params);
  state.loading = false;
  // 成功
  if (result.payload) {
    state.total = result.payload.total;
    state.list = result.payload.list;
  }
}


// 确认出库
export async function confirmOutRecord(copyId: number,clearInput:(input:string)=>void) {
  state.loading = true;
  const result = await confirmOutRecordService({
    copyId,
  });
  state.loading = false;
  // 成功
  if (result.payload) {
      state.currentOutList = [result.payload,...state.currentOutList]
      toast.success("出库成功")
      clearInput("")
  }
}



export async function getShelfLongPage() {
  const result = await getShelfLongPageService({});
  if (result.payload) {
    state.shelfList = result.payload;
  }
}
export async function didMount() {
    getShelfLongPage()
  getOutRecordPage();
}
